import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import { routes } from './routes'
import axios from 'axios'

import { store } from './store/store'




Vue.use(VueRouter);

//配置默认路径
axios.defaults.baseURL = '默认路径';

//配置Vue原型(在任何组件中都可以正常使用，不需要import引入)；
//http这个名词可以随意配置名称，与JS在原型上加入方法一致。
Vue.prototype.http = axios

const router = new VueRouter({
  routes,
  mode: 'history',
  scrollBehavior(to, from, savedPosition) {
    //return {x:0,y:100}
    //return {selector:'./btn'}

    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  }
})

//全局守卫
// router.beforeEach((to, from, next) => {
//   //判断store.gettes.isLogin === false
//   if (to.path == '/login' || to.path == '/register') {
//     next();
//   } else {
//     alert('尚未登录，请先登录！');
//     next('/login');
//   }
// })

//后置钩子
// router.afterEach((to, from) => {

// })

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App),
  store,
}).$mount('#app')
